package com.yc.star.config;

import com.yc.star.job.UserJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Date;
import java.util.concurrent.Callable;

@Configuration
public class QuartzConfig {

    private static final String LIKE_TASK_IDENTITY = "userRedis";//点赞
//    private static final String COUNT_SCORE = "CountScore";

    //定时将点赞数据存到数据库
    @Bean
    public JobDetail quartzDetail(){
        return JobBuilder.newJob(UserJob.class)
                .withIdentity(LIKE_TASK_IDENTITY) //唯一标识
                .storeDurably() //持久化
                .build();
    }

    @Bean
    public Trigger quartzTrigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInMinutes(20) //20分钟执行一次，
                .repeatForever();//无限期重复
        Date now = new Date();
        return TriggerBuilder.newTrigger()
                .forJob(quartzDetail()) //绑定具体的JobDetail实例名
                .withIdentity(LIKE_TASK_IDENTITY) //唯一标识
                .withSchedule(scheduleBuilder) //时间规则
                .startAt(now)
                .build();
    }

//    //定时将评分值存到数据库
//    @Bean
//    public JobDetail quartzDetail2(){
//        return JobBuilder.newJob(MyJob.class).withIdentity(COUNT_SCORE).storeDurably().build();
//    }
//    @Bean
//    public Trigger quartzScore(){
//        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(1)
////                .withIntervalInHours(24*7)//七天执行一次
//                .repeatForever();
//        return TriggerBuilder.newTrigger().forJob(quartzDetail2())
//                .withIdentity(COUNT_SCORE)
//                .withSchedule(scheduleBuilder)
//                .build();
//    }

}
